home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Apache 1.0 / support / httpd_monitor < prev    next >
Text File  |  1995-12-04  |  5KB  |  148 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # ====================================================================
  4. # Copyright (c) 1995 The Apache Group.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. #    notice, this list of conditions and the following disclaimer. 
  12. #
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. #    notice, this list of conditions and the following disclaimer in
  15. #    the documentation and/or other materials provided with the
  16. #    distribution.
  17. #
  18. # 3. All advertising materials mentioning features or use of this
  19. #    software must display the following acknowledgment:
  20. #    "This product includes software developed by the Apache Group
  21. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  22. #
  23. # 4. The names "Apache Server" and "Apache Group" must not be used to
  24. #    endorse or promote products derived from this software without
  25. #    prior written permission.
  26. #
  27. # 5. Redistributions of any form whatsoever must retain the following
  28. #    acknowledgment:
  29. #    "This product includes software developed by the Apache Group
  30. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  31. #
  32. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  33. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  36. # IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  37. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  38. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  40. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  41. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  43. # OF THE POSSIBILITY OF SUCH DAMAGE.
  44. # ====================================================================
  45. #
  46. # This software consists of voluntary contributions made by many
  47. # individuals on behalf of the Apache Group and was originally based
  48. # on public domain software written at the National Center for
  49. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  50. # For more information on the Apache Group and the Apache HTTP server
  51. # project, please see <http://www.apache.org/>.
  52.  
  53.  
  54. # simple script to monitor the child Apache processes
  55. #   Usage:
  56. #      httpd_monitor N     
  57. #                Will give you an update ever N seconds
  58. #                If you choose 0, it might chew up lots of CPU time.
  59. #
  60. # Output explanation..
  61. #
  62. #  s = sleeping but "ready to go" child
  63. #  R = active child
  64. #  _ = dead child (no longer needed)
  65.  
  66.  
  67. $PID_FILE = "/usr/local/httpd/logs/httpd.pid";
  68. $MAX_PROC = 40;    # we never have (or are interested in) more than 40 children
  69.  
  70. #########################################################################
  71. select STDOUT; $| = 1;
  72.  
  73. $delay = @ARGV[0];
  74.  
  75. if ($delay =~ /\-h/i) {
  76.   print STDERR "usage:\n$0 [i]\n  i = interval in seconds (defaults to 1)\n";
  77.   exit(0);
  78. }
  79.  
  80. $delay = 1 unless $delay =~ /^[0-9]+$/;
  81.  
  82. open (P, "$PID_FILE") || die "Unable to open $PID_FILE";
  83. $PID = <P>;
  84. $ext = sprintf("a%05d", $PID);
  85. close(P);
  86.  
  87. open (SB, "/tmp/htstatus.$ext") || die "Unable to open scoreboard file /tmp/htstatus.$ext";
  88.  
  89. $last_len = 0;
  90. while (1) {
  91.  
  92.   if ( ($last_mod = (stat("/tmp/htstatus.$ext"))[9]) != $before) {
  93.     open (SB, "/tmp/htstatus.$ext") || die "Unable to open scoreboard file /tmp/htstatus.$ext";
  94.     seek(SB, 2 , 0);
  95.   
  96.     $len = 0; $pad =""; $running = 0; $dead = 0;  $total=0;
  97.     for ( $child=1; $child<=$MAX_PROC; $child++) {
  98.  
  99.        read(SB, $p1, 1);       # 2nd word = process number
  100.        read(SB, $p2, 1);       # 2nd word = process number
  101.        $p = hex(sprintf("%02X%02X", ord($p1), ord($p2)));
  102.  
  103.        read(SB, $status, 1);  # next byte = status
  104.        $status = ord($status);
  105.      
  106.        read(SB, $junk, 5);    # skip to next entry
  107.           
  108.        $c = sprintf("%X", $child);
  109.        
  110.        if ($p != 0 && $p != $PID) {
  111.          $total++;
  112.          if ($status == 1) {
  113.             $c = "s";
  114.          } else {
  115.             $c = "R";
  116.             ++$running;
  117.          }
  118.          $printed .= "$pad$c";
  119.          
  120.          $pad = ""; 
  121.          $dead = 0;
  122.        } else {
  123.             $dead++;
  124.             $pad = "_"x$dead;
  125.        } 
  126.     }
  127.     $printed .= " ($running/$total)";
  128.     $len = length($printed);  
  129.     
  130.     if ($last_len > $len) {
  131.        print "\010"x$last_len ;
  132.        print " "x$last_len ;
  133.        print "\010"x$last_len ;
  134.     } else {
  135.        print "\010"x$len ;
  136.     }
  137.     print $printed; $printed = "";
  138.  
  139.     $before = $last_mod;
  140.     close(SB);
  141.     $last_len = $len;
  142.    }
  143.    sleep($delay) if $delay >0;
  144. }
  145.  
  146.      
  147.   
  148.